package com.air.antispider.stream.dataprocess.businessprocess

import com.air.antispider.stream.commom.bean._
import com.air.antispider.stream.dataprocess.constants.TravelTypeEnum.TravelTypeEnum

object ConstructorData {

  /**
    * 将散乱的属性封装为一个对象
    * @param requestMethod
    * @param request
    * @param remoteAddr
    * @param httpUserAgent
    * @param timeIso8601
    * @param serverAddr
    * @param highFrqIPGroup
    * @param requestType
    * @param travelType
    * @param cookieValue_JSESSIONID
    * @param cookieValue_USERID
    * @param queryRequestData
    * @param bookRequestData
    * @param httpReferrer
    * @return
    */
  def getProcessedData(requestMethod: String, request: String, remoteAddr: String, httpUserAgent: String,
                       timeIso8601: String, serverAddr: String, highFrqIPGroup: Boolean,
                       requestType: RequestType, travelType: TravelTypeEnum, cookieValue_JSESSIONID: String,
                       cookieValue_USERID: String, queryRequestData: Option[QueryRequestData],
                       bookRequestData: Option[BookRequestData], httpReferrer: String): ProcessedData = {

    //声明核心请求参数的3个字段
    //航班时间
    var flightDate: String = ""
    //目的地
    var depcity: String = ""
    //出发地
    var arrcity: String = ""

    //在queryRequestData中匹配字段数据
    queryRequestData match {
      case Some(queryData) => {
        flightDate = queryData.flightDate
        depcity = queryData.depCity
        arrcity = queryData.arrCity
      }
      case _ =>
    }

    bookRequestData match {
      case Some(bookData) => {
        //如果查询请求参数中有数据,赋值
        if (bookData.flightDate.size > 0 && bookData.depCity.size > 0 && bookData.arrCity.size > 0) {
          flightDate = bookData.flightDate(0)
          depcity = bookData.depCity(0)
          arrcity = bookData.arrCity(0)
        }
      }
      case _ =>
    }

    //封装核心请求参数
    val requestParams: CoreRequestParams = CoreRequestParams(flightDate, depcity, arrcity)

    //将所有参数封装到ProcessedData对象中
    val processedData: ProcessedData = ProcessedData("", requestMethod, request, remoteAddr, httpUserAgent, timeIso8601,
      serverAddr, highFrqIPGroup, requestType, travelType, requestParams, cookieValue_JSESSIONID,
      cookieValue_USERID, queryRequestData, bookRequestData, httpReferrer)
    processedData
  }
}
